package com.yn.admin.controller;


import com.yn.common.model.article.Article;
import com.yn.common.model.article.ArticleContent;
import com.yn.common.model.zy.TCarFleetManageDO;
import com.yn.common.page.BasePage;
import com.yn.common.request.sc.*;
import com.yn.common.response.sc.BaseResult;
import com.yn.common.vo.ArticleInfoVO;
import com.yn.common.vo.ArticleTransitVO;
import com.yn.common.vo.ArticleVo;
import com.yn.service.service.IArticleContentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * 文章内容(科研服务) 前端控制器
 * </p>
 *
 * @author xuquanjun
 * @since 2025-06-26
 */
@RestController
@RequestMapping("api/admin/articleContent")
@Api(tags = "转运文章内容(科研服务)")
@Slf4j
public class ArticleContentAdminController {
    @Autowired
    private IArticleContentService articleContentService;

    /**
     * 新增文章内容
     * @param request 新增文章参数
     * @return
     */
    //@PreAuthorize("hasAnyAuthority('admin:articleContent:save')")
    @ApiOperation(value="新增")
    @PostMapping("/save")
    public BaseResult<String> save(@RequestBody @Validated ArticleTransitRequest request){
        log.info("新增文章内容,{}",request);
        if(articleContentService.create(request)) {
            return BaseResult.success();
        }
        return BaseResult.failed("新增文章内容失败");
    }


    /**
     * 修改文章内容
     */
    //@PreAuthorize("hasAuthority('admin:articleContent:update')")
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public BaseResult<String> update( @RequestBody @Validated ArticleTransitRequest request) {
        log.info("修改文章内容入参,{}", request);
        if (articleContentService.updateArticleContent( request)) {
            return BaseResult.success();
        } else {
            return BaseResult.failed();
        }
    }


    /**
     * 删除文章管理表
     * @param id Integer
     */
    //@PreAuthorize("hasAuthority('admin:articleContent:delete')")
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @ApiImplicitParam(name="id", value="文章ID")
    public BaseResult<String> delete(@RequestParam(value = "id") @NotNull Long id) {
        log.info("删除文章管理表入参,{}", id);
        if (articleContentService.deleteById(id)) {
            return BaseResult.success();
        } else {
            return BaseResult.failed();
        }
    }


    /**
     * 分页显示文章管理表
     * @param request ArticleSearchRequest 搜索条件
     * @param pageParamRequest 分页参数
     */
    //@PreAuthorize("hasAuthority('admin:articleContent:list')")
    @ApiOperation(value = "分页列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public BaseResult<BasePage<ArticleTransitVO>> getList(ArticleTransitSearchRequest request,
                                                          PageParamRequest pageParamRequest) {
        return BaseResult.success(BasePage.restPage(articleContentService.getAdminList(request, pageParamRequest)));
    }


    /**
     * 查询文章转运详情
     * @param id Integer
     */
    //@PreAuthorize("hasAuthority('admin:articleContent:info')")
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/detail/info", method = RequestMethod.GET)
    @ApiImplicitParam(name="id", value="文章ID")
    public BaseResult<ArticleInfoVO> info(@RequestParam(value = "id") @NotNull Long id) {
        return BaseResult.success(articleContentService.getDetail(id));
    }

}
